﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace ObjectLibrary
{
    public class PhysicalEngine
    {
        public const float GRAVITY = 100f;
        private float _archimedesForce = 0;
        private float _mass = 1;
        private Vector3 _velocity = Vector3.Zero;
        public float ArchimedesForce
        {
            get { return _archimedesForce; }
            set { _archimedesForce = value; }
        }
        public Vector3 Velocity
        {
            get { return _velocity; }
            set { _velocity = value; }
        }
        public void setForce(Vector3 f)
        {
            _velocity += f / _mass;
        }
        public void Reset()
        {
            _velocity = Vector3.Zero;
        }
        public void update(double time, bool isOnGround)
        {
            if (isOnGround && _velocity.Y <= 0)
            {
                float f = (GRAVITY - _archimedesForce) * 0.05f;

                _velocity.Y = 0;
                float V = _velocity.Length();
                V = V - f;
                if (V < 0)
                    _velocity = Vector3.Zero;
                else
                {
                    _velocity.Normalize();
                    _velocity = _velocity * V;
                }
            }
            else
            {
                _velocity.Y -= (float)((GRAVITY - _archimedesForce) * time);
            }
        }
        public Vector3 updatePosition(Vector3 pos, double time)
        {
            return pos += _velocity * (float)time;
        }

    }
}
